from langchain_core.prompts import PromptTemplate
from langchain_core.prompts import FewShotPromptTemplate
from langchain_core.example_selectors import LengthBasedExampleSelector

examples = [
    {"input":"happy","output":"sad"},
    {"input":"tall","output":"short"},
    {"input":"energetic","output":"lethargic"},
    {"input":"sunny","output":"gloomy"},
    {"input":"windy","output":"calm"},
]

example_prompt = PromptTemplate(
    input_variables=["input", "output"],
    template="Input:{input}\nOutput:{output}",
)
example_selector = LengthBasedExampleSelector(
    examples=examples, 
    example_prompt=example_prompt,
    max_length=25
)
dynamic_prompt = FewShotPromptTemplate(
    example_selector=example_selector,
    example_prompt=example_prompt,
    prefix="Give the antonym of every input",
    suffix="Input:{adjective}\nOutput:\n\n",
    input_variables=["adjective"],
)

print(dynamic_prompt.format(adjective="big"))

long_string = "big and hug and massive and large and gigantic and tall and much much much much much bigger than everything else"

print(dynamic_prompt.format(adjective=long_string))

